import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'package:flutter_ytx_plugin/src/widget/wx/x5_plugin.dart';
import 'package:flutter_ytx_plugin/src/widget/wx/x5_webview.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    getNativeResult();
    super.initState();
  }

  Future<void> getNativeResult() async {
    // X5Plugin.instance.initX5Sdk();
  }
  X5WebViewController? _controller;

  var progess = 0.0;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              LinearProgressIndicator(
                value: progess,
                minHeight: 10,
                color: Colors.red,
              ),
              TextButton(onPressed: (){
                _controller?.loadUrl("https://zixun.yiqikan8.com/content/80ba4399059e047d.htm?qid=ffdh");
              }, child: Text("loadurl")),

              TextButton(onPressed: (){
                _controller?.reload();
              }, child: Text("reload")),

              TextButton(onPressed: (){
                // X5Plugin.instance.openWebActivity(const <String, dynamic>{
                //   'url': "https://home.firefoxchina.cn/",
                //   'javaScriptEnabled': true,
                //   'domStorageEnabled': true,
                //   "javascriptChannels": [],
                //   "urlInterceptEnabled": true,
                //   "header": {"title": "百度"},
                //   "userAgentString": ""
                // });
              }, child: Text("openWebActivity")), // Expanded(
              //   child: X5WebView(
              //     map: const <String, dynamic>{
              //       'url': "https://home.firefoxchina.cn/",
              //       'javaScriptEnabled': true,
              //       'domStorageEnabled': true,
              //       "javascriptChannels": [],
              //       "urlInterceptEnabled": true,
              //       "header": {"title": "百度"},
              //       "userAgentString": ""
              //     },
              //     onProgressChanged: (value){
              //       setState(() {
              //         progess =1.0* value/100;
              //       });
              //     },
              //     onWebViewCreated: (controller){
              //       _controller=controller;
              //     },
              //
              //   ),
              // ),

            ],
          ),
        ),
      ),
    );
  }
}
